package com.itqf.static_proxy1.impl;

import com.itqf.static_proxy1.UsersService;

/**
 * @Description:
 * @Company: 千锋互联
 * @Author: 李丽婷
 * @Date: 2021/1/14
 * @Time: 上午10:13
 */
public class UsersServiceImplProxy implements UsersService {

    UsersService usersService;

    //被代理类
    public  UsersServiceImplProxy(UsersService usersService){
         this.usersService = usersService;
    }


    @Override
    public void add() {
        try {
            System.out.println("开启事务");
            usersService.add();
            System.out.println("提交事务");
        } catch (Exception e) {
            System.out.println("回滚事务");
        }

    }

    @Override
    public void delete() {
        try {
            System.out.println("开启事务");
            usersService.delete();
            System.out.println("提交事务");
        } catch (Exception e) {
            System.out.println("回滚事务");
        }
    }

    @Override
    public void update() {
        try {
            System.out.println("开启事务");
            usersService.update();
            System.out.println("提交事务");
        } catch (Exception e) {
            System.out.println("回滚事务");
        }
    }
}
